package leetcode.zs239;

/**
 * @author: trtan
 * @create: 2021-05-08 17:09
 * @description:
 **/
public class Two {
    public static void main(String[] args) {
        System.out.println(new Two().splitString("200100"));
    }

    public boolean splitString(String s) {
        long pre = 0;
        for(int i = 0; i < s.length(); i++) {
            int ch = s.charAt(i) - '0';
            pre = pre * 10 + ch;
            if (pre > 10000_0000_000L) {
                return false;
            }
            if(check(s, pre, 0, i + 1)) {
                return true;
            }
        }
        return false;
    }

    public boolean check(String s, long pre, long now, int k) {
        boolean flag = false;
        while(k < s.length()) {
            int ch = s.charAt(k) - '0';
            now = now * 10 + ch;
            if(now >= pre) {
                return false;
            }
            if(pre - now == 1) {
                if (now > 0 || k == s.length() - 1) {
                    pre = now;
                    now = 0;
                    flag = true;
                } else {
                    flag = false;
                }
            } else {
                flag = false;
            }
            k++;
        }
        return flag;
    }
}
